package com.auction.service.impl;

import com.auction.common.dao.MyBaseServiceImpl;
import com.auction.entity.Shop;
import com.auction.entity.ShopUser;
import com.auction.mapper.ShopMapper;
import com.auction.mapper.ShopUserMapper;
import com.auction.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

import static com.auction.common.utils.Assert.isSuccess;
@Service
public class ShopImpl extends MyBaseServiceImpl<Shop, ShopMapper> implements ShopService {
    @Autowired
    ShopMapper shopMapper;
    @Autowired
    ShopUserMapper shopUserMapper;

    @Transactional
    @Override
    public int shopAdd(Shop s) {
        //生成店铺code值
            //d+当前时间+id
            //获得当前时间
            Date now = new Date();
            long time = now.getTime();
        s.setCode("d"+time);
        //断言判断
        isSuccess((shopMapper.insert(s)),"添加店铺失败");
        //断言判断
        System.out.println(s.getId());
        ShopUser shopUser = s.getSu();
        shopUser.setShop_id(s.getId());
        isSuccess((shopUserMapper.insert(shopUser)),"添加店铺法人信息失败");
        return 1;
    }

    @Override
    public int updateStatus(Integer id, Integer status) {
        return shopMapper.updateStatus(id,status);
    }
}
